package itheima.com.Day15.socketdemo8;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket ss =new ServerSocket(10000);
        while (true) {
            Socket accept = ss.accept();
            //创建网络输入流 准备读取数据
            BufferedInputStream bis = new BufferedInputStream(accept.getInputStream());

            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("Day15\\src\\Server"+ UUID.randomUUID().toString()+".1jpg"));

            int p;
            while ((p=bis.read())!=-1){
                bos.write(p);
            }

            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
            bw.write("上传成功咯");
            bw.newLine();
            bw.flush();

            accept.close();
            bos.close();
        }
//        ss.close();
    }
}
